package com.efuture.vdrp.android.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class JinHuoServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		response.setContentType("text/html");
		System.out.println("OPIPPOIP");
		String str = null;
		//MySQL sql = new MySQL();
		WebApplicationContext webcontext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
		MySQL sql =(MySQL)webcontext.getBean("MySQL");
		java.io.ObjectInputStream in = new java.io.ObjectInputStream(request
				.getInputStream());
		try {
			PrintWriter out = response.getWriter();
			ArrayList list = (ArrayList) in.readObject();
			HashMap map = (HashMap) list.get(0);
			String unitname = (String) map.get("unitname");
			String empname = (String) map.get("empname");
			String storagename = (String) map.get("storagename");
			System.out.println(unitname + empname + storagename + "JKL");
			sql.jinhuodanInsert(unitname, empname, storagename);
			for (int i = 0; i < list.size(); i++) {
				System.out.println("list :" + list.size());
				HashMap map1 = (HashMap) list.get(i);
				String goodname = (String) map1.get("goodname");
				int amount = Integer.parseInt((String) map1.get("amount"));
				float price = Float.valueOf((String) map1.get("price"));
				double total = Double.valueOf((String) map1.get("total"));
				String storagename1 = (String) map.get("storagename");
				System.out.println(goodname + "" + price + "" + total + ""
						+ "++++++++++++");
				str = sql.jinhuodan(goodname, amount, price, total,
						storagename1);
			}
			out.println(str);
			out.flush();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
